home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 642 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: gate.net!mlbfl2-4
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Binary Tree and MSC/C++7.00
  5. Date: 8 Jan 1996 02:57:11 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4cq167$kfu@news.gate.net>
  8. References: <HAKOLA.96Jan7002825@lk-hp-16.hut.fi>
  9. NNTP-Posting-Host: pslfl2-7.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <HAKOLA.96Jan7002825@lk-hp-16.hut.fi>,
  13.    hakola@snakemail.hut.fi (Petri Hakola) wrote:
  14. >
  15. >    It seems to me that I suffer some kind of partial amnesia. I
  16. >    can build a binary tree, add stuff to it, but how do I destroy
  17. >    it. I've tried nearly everyting, but there's either General
  18. >    Protection Error or some remains of prior members. I have
  19. >    quite embarassing feeling that I have forget something so
  20. >    obvious that it should almost 'hit the eye', but...
  21. >
  22. >        if(root == NULL)
  23. >                  return;
  24. >                delete_tree(root->left);
  25. >                  free(root);
  26.                    ^^^^^^^^^^
  27.  
  28. At this point, is *root* a valid pointer? No.
  29.  
  30. >        delete_tree(root->right);
  31.                             ^^^^
  32. But you use it anyway.
  33.  
  34. Delete (free) both left and right branches *before* freeing *this* pointer. 
  35. That would hold true for any allocation units pointed to from within *this* 
  36. allocation unit.
  37.  
  38. >
  39. >    Is this correct or ?
  40. >
  41. >    And then some problems with strings. Is it common that while
  42. >    coding using Microsoft Programmers Workbench, strings aren't
  43. >    what they're supposed to be. For examble, if I use strncat to
  44.  
  45. No. 99.9999999% programmer error.
  46.  
  47. >    cut string from 100 char to 45 char, string is cut, but if I
  48. >    print it using printf, first 45 chars come out ok, but rest of
  49. >    the string is filled with smiling faces and all sorts of
  50. >    'exotic' characters. Like '\0' isn't there or something...
  51.  
  52. <snip>
  53.  
  54. Post your code so we can have a look.
  55.  
  56. Bill
  57.  
  58. "Whatcha got on?...Your mind?"
  59.